package com.LeeCode;

/**
 * 删除字符使字符串变好
 */

public class Code1957 {
    public static void main(String[] args) {
        String s = "aaabaaaa";
        System.out.println(new Code1957().makeFancyString(s));
    }

    public String makeFancyString(String s) {
        char[] chars = s.toCharArray();
        StringBuilder ans = new StringBuilder();
        ans.append(chars[0]);
        int count = 1;
        char curChar = chars[0];
        for (int i = 1; i < chars.length; i++) {
            if (curChar == chars[i]) {
                count++;
                if (count < 3) ans.append(curChar);
            } else {
                curChar = chars[i];
                count = 1;
                ans.append(curChar);
            }
        }
        return ans.toString();
    }
}
